package cn.tedu.hotel_management_system.service.impl;

import cn.tedu.hotel_management_system.base.json_result.ResultDataDto;
import cn.tedu.hotel_management_system.base.json_result.ResultDto;
import cn.tedu.hotel_management_system.mapper.InRoomInfoMapper;
import cn.tedu.hotel_management_system.pojo.dto.InRoomInfoFormDto;
import cn.tedu.hotel_management_system.pojo.dto.InRoomInfoUpdateDto;
import cn.tedu.hotel_management_system.pojo.entity.InRoomInfos;
import cn.tedu.hotel_management_system.service.InRoomManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InRoomManagementServiceImpl implements InRoomManagementService {

    @Autowired
    InRoomInfoMapper mapper;

    @Override
    public ResultDto<InRoomInfoFormDto> addInRoom(InRoomInfoFormDto inRoomInfoFormDto) {
        ResultDto resultDto=new ResultDto();
        if(mapper.addInRoom(inRoomInfoFormDto)!=1){
            resultDto.setIsSuccess(false);
            resultDto.setMes("添加失败");
            return resultDto;
        }
        resultDto.setIsSuccess(true);
        resultDto.setMes("添加成功!");
        return resultDto;
    }

    @Override
    public ResultDto deleteById(Long id) {
        ResultDto resultDto=new ResultDto();
        if(mapper.deleteById(id)!=1){
            resultDto.setIsSuccess(false);
            resultDto.setMes("删除失败");
            return resultDto;
        }
        resultDto.setIsSuccess(true);
        resultDto.setMes("删除成功");
        return resultDto;
    }

    @Override
    public ResultDto updateById(InRoomInfoUpdateDto inRoomInfoUpdateDto) {
        ResultDto resultDto=new ResultDto();
        if(mapper.updateById(inRoomInfoUpdateDto)!=1){
            resultDto.setIsSuccess(false);
            resultDto.setMes("修改失败");
            return resultDto;
        }
        resultDto.setIsSuccess(true);
        resultDto.setMes("修改成功");
        return resultDto;
    }

    @Override
    public ResultDataDto<InRoomInfos> list() {
        ResultDataDto<InRoomInfos> resultDataDto=new ResultDataDto();
        List<InRoomInfos> list = mapper.list();
        resultDataDto.setDataList(list);
        return resultDataDto;
    }

}
